#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>

struct Point
{
    int row;
    int col;

    //构造函数1
    Point()
    {
        row=-1;
        col=-1;
    }


    //构造函数2
    Point(int r,int c)
    {
        row=r;
        col=c;
    }
};

struct Node
{
    Point p;//存储要落子的点

    std::vector<Node>::iterator* f;//指向父节点
    std::vector<Node> s;//存储子节点

    //构造函数
    Node(Point x)
    {
        p.col=x.col;
        p.row=x.row;
    }
};

class Widget : public QWidget
{
    Q_OBJECT

public:
    int widgetWidth=600;
    int widgetHeight=600;

    //棋盘格
    int blockWidth=600/17;

    int BOARDSIZE=16;

    int PLAYER;
    int COMPUTER;

    int EMPTY=0;

    std::vector<std::vector<int>> gameMapVec; // 存储当前游戏棋盘和棋子的情况,空白为0，白子1，黑子-1
    //std::vector<std::vector<int>> scoreMapVec; // 存储各个点位的评分情况，作为AI下棋依据
    std::vector<std::vector<int>> tempMapVec; // 用于复制gameMapVec和临时存储现在要估值的棋局

    //std::vector<Node> rootNode; // 用于存储第一层的根节点

    int order=0;//order为偶数下黑棋，为奇数下白棋
    //int fakeOrder=0;//用于AI判断时候改变order

    //用于探测八个方向
    QPoint m_offset[8] = {
        QPoint(0,-1),QPoint(1,-1),QPoint(1,0),QPoint(1,1),
        QPoint(0,1),QPoint(-1,1),QPoint(-1,0),QPoint(-1,-1)
    };

    Widget(QWidget *parent = 0);

    void paintEvent(QPaintEvent *event);

    //void mouseMoveEvent(QMouseEvent *event);

    void mousePressEvent(QMouseEvent *event);

    bool judgeWinner(int,int);//判断输赢

    int getPointAt(Point p, int dir, int offset);

    int evaluate(Point p,int who);

    bool isNotNull(Point p);

    void dropChessAt(Point p);

    void fakeDropChessAt(Point p,int object);

    void isTimeToAI();

    Point gameTreeBestPos();

    ~Widget();
};

#endif // WIDGET_H
